﻿//Copyright (c) Microsoft Corporation.  All rights reserved.

using Microsoft.Ted.Wacel.Base;

namespace Microsoft.Ted.Wacel.Redis
{
    public class CircularBuffer<T>: Base.CircularBuffer<byte[]>
    {
        public CircularBuffer(string name, long size, string hostName, int port = 6379,string password = null)
               : base(name, size,
                    new RedisCacheProvider(new BookSleeve.RedisConnection(hostName, port, allowAdmin: true, password: password), name),
                    new RedisLockProvider(new BookSleeve.RedisConnection(hostName, port, allowAdmin: true, password: password), name + ":lock"))
        {  
        }
        public void Add(T item)
        {
            base.Add(JsonSerializer.Serialize(item.GetType(), item));
        }
        public new  T this[long key]
        {
            get
            {
                return (T)JsonSerializer.Deserialize(typeof(T), base[key]);
            }
        }
    }
}
